package com.wsd.serviceImpl;

import com.wsd.dao.LoanInformationMapper;
import com.wsd.dao.RepaymentPlanMapper;
import com.wsd.domain.NormalLoan;
import com.wsd.domain.OverdueLoan;
import com.wsd.service.LOverdueLoanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Classname LOverdueLoanServiceImpl
 * @Description TODO
 * @Date 2020/7/20 11:06
 * @Created by niuxiaojuan
 */
@Service
public class LOverdueLoanServiceImpl implements LOverdueLoanService {
    @Autowired
    RepaymentPlanMapper repaymentPlanMapper;
    @Autowired
    LoanInformationMapper loanInformationMapper;
    @Override
    public BigDecimal sumLOverdueLoan(){
        List<Long> list=repaymentPlanMapper.findLOverdueGroup();
        return loanInformationMapper.sumLoanMoney(list);
    }

    @Override
    public BigDecimal sumRepayLoanMoney() {
        List<Long> list=repaymentPlanMapper.findLOverdueGroup();
        BigDecimal remianMoney=loanInformationMapper.sumRemainPrincipal(list);
        return loanInformationMapper.sumLoanMoney(list).subtract(remianMoney);
    }

    @Override
    public BigDecimal findLOverInterest() {
        return repaymentPlanMapper.findLOverInterest();
    }

    @Override
    public BigDecimal sumRepayInterest() {
        return repaymentPlanMapper.sumRepayInterest(repaymentPlanMapper.findLOverdueGroup());
    }

    @Override
    public BigDecimal sumLOverdueMoney() {
        return repaymentPlanMapper.sumLOverdueMoney();
    }

    //长期逾期贷款逾期总利息
    @Override
    public BigDecimal sumLOverdueInterest() {
        return repaymentPlanMapper.sumLOverdueInterest();
    }

    @Override
    public List<OverdueLoan> findLOverLoanForm(int pagenum,int num) {
        List<OverdueLoan> list=repaymentPlanMapper.findLOverLoanForm((pagenum-1)*num,num);
        for(OverdueLoan n:list)
        {
            NormalLoan temp=loanInformationMapper.findFormInfoById(n.getLoanId());
            n.setUserId(temp.getUserId());
            n.setLoanAmount(temp.getLoanAmount());
            n.setRepayAmount(temp.getRepayAmount());
        }
        return list;
    }

    @Override
    public Long countLOverLoanForm() {
        return repaymentPlanMapper.countLOverLoanForm();
    }

}
